function trueeOpen(arr) {
    return arr.reduce((acc, cur) => {
        if (Array.isArray(cur.subs)) {
            const copyCur = { ...cur }
            delete copyCur.subs
            return acc.concat(copyCur, trueeOpen(cur.subs))
        } else {
            return acc.concat(cur)
        }
    }, [])
}


export default {
    namespaced: true,
    state: () => ({
        tabIndex: 0,
        powerList: [],
        linePowerList: [],
        createOrderPromiseResolve: null,
    }),
    mutations: {
        SET_TAB_INDEX(state, tabIndex) {
            state.tabIndex = tabIndex;
        },
        SET_POWER_LIST(state, powerList) {
            state.powerList = powerList;
            state.linePowerList = trueeOpen(powerList);
            uni.setStorageSync("powerList", powerList);
        },
        SET_CREATE_ORDER_PROMISE_RESOLVE(state, createOrderPromiseResolve) {
            state.createOrderPromiseResolve = createOrderPromiseResolve;
        },
    },
};
